<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript">

    $(function () {

        toggleOptional();
        $('#area').hide();
        $('#show-btn').show();
        $('#hide-btn').hide();
        $('#planServeyor').hide();

        $('#planNumber').bind('blur', function () {
            showHidePlanInfo($('#planNumber').val());
        });
        showHidePlanInfo($('#planNumber').val());

        disablePaste(new Array(
                'hectareId',
                'acreId',
                'roodsId',
                'perchesId'
        ));
    });
    $(function () {
      //  alert($("input#userRole").val());
       if($("input#userRole").val() != "SC" || $("input#editMode").val() == 2 ){
           //alert("In If");
           disableLandInformation() ;
           //disableAlienationFields();
       }
    });

    function showHidePlanInfo(planNo) {
        if (planNo.length > 0) {
            $('#planServeyor').show();
        } else {
            $('#planServeyor').hide();
        }
    }

    function disableLandInformation() {
        var fields = new Array(
                'districtId',
                'railwayTrackId',
                'districtEngineerZoneId',
                'IPWZoneId',
                'railwayProtectionZoneId',
                'nearestRailwayStationId',
                'fileNoId',
                'village',
                'planNumber',
                'lotNumber',
                'planDate',
                'hectareId',
                'acreId',
                'roodsId',
                'perchesId',
                'northBoundary',
                'northEastBoundary',
                'eastBoundary',
                'southEastBoundary',
                'southBoundary',
                'southWestBoundary',
                'westBoundary',
                'northWestBoundary',
                'northBoundaryType',
                'northEastBoundaryType',
                'eastBoundaryType',
                'southEastBoundaryType',
                'southBoundaryType',
                'southWestBoundaryType',
                'westBoundaryType',
                'northWestBoundaryType',
                'landComment',
                'geologicalTypeId',
                'locationFromMileId',
                'locationFromChainId',
                'locationToMileId',
                'locationToChainId',
                'otherLocationId',
                'surveyor'

               /* 'alienationMethodSelectedList-1',
                'alienationMethodSelectedList-2',
                'alienationMethodSelectedList-3',
                'alienationMethodSelectedList-4',
                'alienationMethodSelectedList-5',
                'alienationMethodSelectedList-6',
                'alienationMethodSelectedList-7'*/
        );
       disableFields(fields);
    }


    function toggleOptional() {
        $('.optional-boundary').toggle();
        $('#show-btn').toggle();
        $('#hide-btn').toggle();
    }

    $(document).ready(function () {
        changeHectareKml();
    });

    function searchLand() {
        var landId = $('#parentSerialNumber').val();
        var url = '${pageContext.request.contextPath}' + '/viewDetailLandReportByAttachLand.do?landId=' + landId + ' ';

        myWindow = window.open(url, '', 'width=980,height=500,scrollbars=yes');
        myWindow.focus();
    }

    ////////////////////////////////////////////////////////////////////////////////////
    $(function () {
        $('select#railwayTrackId').bind('change', function (evt1) {
            var id = $("select#railwayTrackId").attr("value");
            $.getJSON('${pageContext.request.contextPath}/common/DivisionLookupService', {id: id, mode: 1},
                function (data) {
                    var options1 = '<option value="0">' + $('#select').val() + '</option> ';
                    var ds = data.rpZoneList;
                    for (var i = 0; i < ds.length; i++) {
                        options1 += '<option value="' + ds[i].optionValue + '">' + ds[i].optionDisplay + '</option>'
                    }
                    $("select#railwayProtectionZoneId").html(options1);
                    var options2 = '<option value="0">' + $('#select').val() + '</option> ';
                    $("select#IPWZoneId").html(options2);
                    $("select#nearestRailwayStationId").html(options2);
                });
        });

        $('select#railwayProtectionZoneId').bind('change', function (evt1) {
            var id = $("select#railwayTrackId").attr("value");
            $.getJSON('${pageContext.request.contextPath}/common/DivisionLookupService', {id: id, mode: 2},
                    function (data) {
                        var options1 = '<option value="0">' + $('#select').val() + '</option> ';
                        var ds = data.ipwZoneList;
                        for (var i = 0; i < ds.length; i++) {
                            options1 += '<option value="' + ds[i].optionValue + '">' + ds[i].optionDisplay + '</option>'
                        }
                        $("select#IPWZoneId").html(options1);
                        var options2 = '<option value="0">' + $('#select').val() + '</option> ';
                        $("select#nearestRailwayStationId").html(options2);
                    });
        });

        $('select#IPWZoneId').bind('change', function (evt1) {
            var ipw = $("select#IPWZoneId").attr("value");
            var rpf = $('select#railwayProtectionZoneId').attr("value");
            $.getJSON('${pageContext.request.contextPath}/common/DivisionLookupService', {id: ipw, rpf: rpf , mode: 3},
                    function (data) {
                        var options1 = '<option value="0">' + $('#select').val() + '</option> ';
                        var ds = data.railStationList;
                        for (var i = 0; i < ds.length; i++) {
                            options1 += '<option value="' + ds[i].optionValue + '">' + ds[i].optionDisplay + '</option>'
                        }
                        $("select#nearestRailwayStationId").html(options1);
                        //var options2 = '<option value="0">' + $('#all').val() + '</option> ';
                        //$("select#nearestRailwayStationId").html(options2);
                    });
        });
    });
</script>
<div class="left-align">
    <s:checkbox id="ignoreWarn" label="Add" name="ignoreWarnings" value="ignoreWarn" fieldValue="true"/>
    <s:label value="Ignore Warnings"/>
</div>

<fieldset>
<table class="width-100">
    <tr>

        <td class="left-align"><s:label value="%{getText('district.label')}"/><span class="mandatory-field"></span></td>
        <td>
            <s:select list="districtList" name="land.district.id" headerKey="0" headerValue="%{getText('select.label')}"
                      id="districtId"/>
        </td>
        <td class="left-align"><s:label value="Railway Track"/><span class="mandatory-field"></span></td>
        <td>
            <s:select name="land.railwayTrack.id" id="railwayTrackId" headerKey="0"
                      headerValue="%{getText('select.label')}"
                      list="railwayTrackList" cssClass="width-200-px"/>
        </td>
    </tr>
    <tr>
        <%--<td><s:label value="%{getText('gn_division.label')}"/><span class="mandatory-field"></span></td>--%>
        <td><s:label value="District Engineer Zone"/><span class="mandatory-field"></span></td>
        <td>
            <s:if test="viewMode">
                <%--<s:textfield id="districtEngineerZoneId" name="land.districtEngineerZone.id" cssClass="width-200-px"/>--%>
            </s:if>
            <s:else>
                <s:select id="districtEngineerZoneId" name="land.districtEngineerZone.id"
                          list="districtEngineerZoneList" headerKey="0"
                          headerValue="%{getText('select.label')}" cssClass="width-200-px"/>
            </s:else>
        </td>
        <td><s:label value="Railway Protection Zone"/></td>
        <td>
            <s:if test="viewMode">
                <%--<s:textfield id="gnDivisionId" name="land.railwayProtectionZone.id" cssClass="width-200-px"/>--%>
            </s:if>
            <s:else>
                <s:select id="railwayProtectionZoneId" name="land.railwayProtectionZone.id" list="railwayProtectionZoneList" headerKey="0"
                          headerValue="%{getText('select.label')}" cssClass="width-200-px"/>
            </s:else>
        </td>
    </tr>

    <tr>
        <%--<td><s:label value="%{getText('gn_division.label')}"/><span class="mandatory-field"></span></td>--%>
        <td><s:label value="IPW Zone"/><span class="mandatory-field"></span></td>
        <td>
            <s:if test="viewMode">
                <%--<s:textfield id="1" name="land.ipwZone.id" cssClass="width-200-px"/>--%>
            </s:if>
            <s:else>
                <s:select id="IPWZoneId" name="land.ipwZone.id" list="IPWZoneList"
                          cssClass="width-200-px" headerKey="0" headerValue="%{getText('select.label')}"/>
            </s:else>
        </td>
        <td><s:label value="Nearest Railway Station"/></td>
        <td>
            <s:if test="viewMode">
                <s:textfield id="nearestRailwayStationId" name="land.nearestRailwayStation.id" cssClass="width-200-px"/>
            </s:if>
            <s:else>
                <s:select id="nearestRailwayStationId" name="land.nearestRailwayStation.id" list="railwayStationList"
                          cssClass="width-200-px" headerKey="0" headerValue="%{getText('select.label')}"/>
            </s:else>
        </td>
    </tr>

    <tr>
        <%--<td><s:label value="%{getText('name_of_the_land.label')}"/><span class="mandatory-field"></span></td>--%>
        <td><s:label value="File No"/><span class="mandatory-field"></span></td>
        <td><s:textfield name="land.landFileNumber" id="fileNoId" cssClass="width-200-px"/></td>
        <td><s:label value="%{getText('village.label')}"/></td>
        <td><s:textfield name="land.village" id="village" cssClass="width-200-px"/></td>
    </tr>
    <tr>
        <td><s:label value="%{getText('plan_no.label')}"/></td>
        <td><s:textfield name="land.planNumber" id="planNumber" cssStyle="width: 200px;"/></td>
        <td><s:label value="%{getText('lot_no.label')}"/></td>
        <td><s:textfield name="land.lotNumber" id="lotNumber" cssStyle="width: 200px;"/></td>
    </tr>
    <tr id="planServeyor">
        <td><s:label value="%{getText('surveyor.label')}"/></td>
        <s:if test="land.mode.ordinal() == 1">
            <td><s:textfield name="land.surveyor" id="surveyor"
                             cssClass="width-200-px"/></td>
        </s:if>
        <s:else>
            <td><s:textfield name="land.surveyor" id="surveyor" value="%{getText('servey_general.label')}"
                             cssClass="width-200-px"/></td>
        </s:else>

        <td><s:label value="%{getText('plan_date.label')}"/> <s:label value="%{getText('date_format.label')}"
                                                                      cssClass="date-format"/></td>
        <td><s:textfield id="planDate" name="land.planDate" cssClass="width-200-px"/></td>
    </tr>
    <tr>
        <td><s:label value="%{getText('geological_type.label')}"/></td>
        <td class="left-align" colspan="3">
            <s:if test="viewMode">
                <s:textfield id="geologicalTypeId" name="land.geologicalType.name" cssClass="width-200-px"/>
            </s:if>
            <s:else>
                <s:select id="geologicalTypeId" name="land.geologicalType.id"
                          list="geologicalTypeList" headerKey="0"
                          headerValue="%{getText('select.label')}" cssClass="width-200-px"/>
            </s:else>
        </td>
    </tr>

    <table class="width-70">
        <tr>
            <td><s:label value="Start Location"/></td>
            <td class="right-align"><s:label value="Mile: "/></td>
            <td class="left-align">
                <s:textfield id="locationFromMileId" name="land.landLocation.fromMile" cssClass="width-80-px"
                             onKeyPress="return numbersonly(event,true)"/>
            </td>
            <td class="right-align"><s:label value="Chain: "/></td>
            <td class="left-align">
                <s:textfield id="locationFromChainId" name="land.landLocation.fromChain" cssClass="width-80-px"
                             onKeyPress="return numbersonly(event,true)"/>
            </td>
        </tr>
        <tr>
            <td><s:label value="End Location"/></td>
            <td class="right-align"><s:label value="Mile: "/></td>
            <td class="left-align">
                <s:textfield id="locationToMileId" name="land.landLocation.toMile" cssClass="width-80-px"
                             onKeyPress="return numbersonly(event,true)"/>
            </td>
            <td class="right-align"><s:label value="Chain: "/></td>
            <td class="left-align">
                <s:textfield id="locationToChainId" name="land.landLocation.toChain" cssClass="width-80-px"
                             onKeyPress="return numbersonly(event,true)"/>
            </td>
        </tr>
        <tr>
            <td><%--<s:checkbox name="other" fieldValue="true" label="Other"/>--%><s:label value="Other"/></td>
            <td colspan="5">
                <s:textfield id="otherLocationId" name="land.landLocation.locationDetail" cssClass="width-200-px"/>
            </td>
        </tr>
    </table>
</table>

<table>
    <tr>
        <td><s:label value="%{getText('extent_of_the_land.label')}"/></td>
        <td colspan="3">
            <table class="width-100">
                <tr>
                    <td><s:label value="%{getText('hectare.label')}"/></td>
                    <td colspan="3"><s:textfield id="hectareId" name="hectare" cssStyle="width: 80px;"
                                                 onKeyPress="return numbersonly(event,true)"/></td>

                </tr>

                <tr>
                    <td><s:label value="%{getText('acre.label')}"/></td>
                    <td><s:textfield id="acreId" name="acre" cssStyle="width: 80px;"
                                     onKeyPress="return numbersonly(event,true)"/></td>
                    <td><s:label value="%{getText('roods.label')}"/></td>
                    <td><s:textfield id="roodsId" name="roods" cssStyle="width: 80px;"
                                     onKeyPress="return numbersonly(event,true)"/></td>
                    <td><s:label value="%{getText('perches.label')}"/></td>
                    <td><s:textfield id="perchesId" name="perches" cssStyle="width: 80px;"
                                     onKeyPress="return numbersonly(event,true)"/></td>
                </tr>

                <tr>
                    <%--<td><s:label value="%{getText('hectare_in_word.label')}"/></td>
                    <td colspan="3">--%>
                        <%--<s:textarea id="areaInWordId" name="land.areaInWord" cssClass="width-200-px"--%>
                        <%--rows="2"/>--%>
                   <%-- </td>--%>
                </tr>

            </table>
        </td>
    </tr>
    <tr>
        <td><s:label value="%{getText('boundaries.label')}"/></td>
        <td colspan="3">
            <table class="width-100">
                <tr>
                    <td class="width-120-px"><s:label value="%{getText('north.label')}"/></td>
                    <td><s:textarea id="northBoundary" name="land.northBoundary" cssClass="width-250-px" rows="1"/></td>
                    <s:if test="viewMode">
                        <td><s:textfield name="land.northBoundaryType.id" cssClass="width-150-px"
                                         id="northBoundaryType"/></td>
                    </s:if>
                    <s:else>
                        <td><s:select name="land.northBoundaryType.id" cssClass="width-150-px" id="northBoundaryType"
                                      list="boundaryTypeList" headerKey="0"
                                      headerValue="%{getText('select.label')}"/></td>
                    </s:else>
                </tr>
                <tr>
                    <td><s:label value="%{getText('east.label')}"/></td>
                    <td><s:textarea id="eastBoundary" name="land.eastBoundary" cssClass="width-250-px" rows="1"/></td>
                    <s:if test="viewMode">
                        <td><s:textfield name="land.eastBoundaryType.id" cssClass="width-150-px"
                                         id="eastBoundaryType"/></td>
                    </s:if>
                    <s:else>
                        <td><s:select name="land.eastBoundaryType.id" cssClass="width-150-px" id="eastBoundaryType"
                                      list="boundaryTypeList" headerKey="0"
                                      headerValue="%{getText('select.label')}"/></td>
                    </s:else>
                </tr>
                <tr>
                    <td><s:label value="%{getText('south.label')}"/></td>
                    <td><s:textarea id="southBoundary" name="land.southBoundary" cssClass="width-250-px" rows="1"/></td>
                    <s:if test="viewMode">
                        <td><s:textfield name="land.southBoundaryType.id" cssClass="width-150-px"
                                         id="southBoundaryType"/></td>
                    </s:if>
                    <s:else>
                        <td><s:select name="land.southBoundaryType.id" cssClass="width-150-px" id="southBoundaryType"
                                      list="boundaryTypeList" headerKey="0"
                                      headerValue="%{getText('select.label')}"/></td>
                    </s:else>
                </tr>
                <tr>
                    <td><s:label value="%{getText('west.label')}"/></td>
                    <td><s:textarea id="westBoundary" name="land.westBoundary" cssClass="width-250-px" rows="1"/></td>
                    <s:if test="viewMode">
                        <td><s:textfield name="land.westBoundaryType.id" cssClass="width-150-px"
                                         id="westBoundaryType"/></td>
                    </s:if>
                    <s:else>
                        <td><s:select name="land.westBoundaryType.id" cssClass="width-150-px" id="westBoundaryType"
                                      list="boundaryTypeList" headerKey="0"
                                      headerValue="%{getText('select.label')}"/></td>
                    </s:else>
                </tr>
                <s:if test="!viewMode">
                    <tr class="optional-boundary">
                        <td><s:label value="%{getText('north_east.label')}"/></td>
                        <td><s:textarea id="northEastBoundary" name="land.northEastBoundary" cssClass="width-250-px"
                                        rows="1"/></td>
                        <td><s:select name="land.northEastBoundaryType.id" cssClass="width-150-px"
                                      id="northEastBoundaryType"
                                      list="boundaryTypeList" headerKey="0"
                                      headerValue="%{getText('select.label')}"/></td>
                    </tr>
                    <tr class="optional-boundary">
                        <td><s:label value="%{getText('south_east.label')}"/></td>
                        <td><s:textarea id="southEastBoundary" name="land.southEastBoundary" cssClass="width-250-px"
                                        rows="1"/></td>
                        <td><s:select name="land.southEastBoundaryType.id" cssClass="width-150-px"
                                      id="southEastBoundaryType"
                                      list="boundaryTypeList" headerKey="0"
                                      headerValue="%{getText('select.label')}"/></td>
                    </tr>
                    <tr class="optional-boundary">
                        <td><s:label value="%{getText('south_west.label')}"/></td>
                        <td><s:textarea id="southWestBoundary" name="land.southWestBoundary" cssClass="width-250-px"
                                        rows="1"/></td>
                        <td><s:select name="land.southWestBoundaryType.id" cssClass="width-150-px"
                                      id="southWestBoundaryType"
                                      list="boundaryTypeList" headerKey="0"
                                      headerValue="%{getText('select.label')}"/></td>
                    </tr>
                    <tr class="optional-boundary">
                        <td><s:label value="%{getText('north_west.label')}"/></td>
                        <td><s:textarea id="northWestBoundary" name="land.northWestBoundary" cssClass="width-250-px"
                                        rows="1"/></td>
                        <td><s:select name="land.northWestBoundaryType.id" cssClass="width-150-px"
                                      id="northWestBoundaryType"
                                      list="boundaryTypeList" headerKey="0"
                                      headerValue="%{getText('select.label')}"/></td>
                    </tr>
                </s:if>
                <tr align="right">
                    <td colspan="2"></td>
                    <td>
                        <s:submit onclick="toggleOptional(); return false;" id="show-btn"
                                  value="%{getText('show_other_boundaries.label')}"/>
                        <s:submit onclick="toggleOptional(); return false;" id="hide-btn"
                                  value="%{getText('hide_other_boundaries.label')}"/>
                    </td>
                </tr>

            </table>
        </td>
    </tr>

    <tr>
        <td><s:label value="%{getText('comment_about_land.label')}"/></td>
        <td colspan="3">
            <s:textarea id="landComment" cssClass="width-595-px"
                        name="land.landVisitComment" rows="5"/>
        </td>
    </tr>


</table>


<s:if test="!viewMode">
    <%--<s:include value="../documentUpload.jsp"/>--%>
</s:if>
</fieldset>
<s:hidden id="landId" name="land.id"/>
<s:hidden name="land.version"/>
<s:hidden name="land.comment"/>
<s:hidden id="landExtent" name="land.landExtent"/>
<s:hidden id="approvalState" name="alienation.approvalState"/>
<s:hidden id="pls_select_gnDivision" value="%{getText('pls_select_gnDivision.label')}"/>
